// 树状结构数据
export function deepTree(list) {
    const result = [];

    const map = {};

    for (let item of list) {
        // 浅拷贝防止修改原对象
        map[item.id] = { ...item };
    };

    for (let item of list) {
        if (!item.parentId) {
            result.push(map[item.id]);
        } else {
            if (map[item.parentId].children) {
                map[item.parentId].children.push(map[item.id])
            } else {
                map[item.parentId].children = [map[item.id]]
            }
        }
    }
    return result;

};

// 判断id是否为叶子节点
export function isLeaf(list, id) {
    return list.every((item) => item.parentId !== id);
  }